#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution
{
public:
    bool wordBreak(string s, vector<string>& wordDict)
    {
        int n = s.size();
        vector<bool> dp(n + 1, false);
        dp[0] = true;
        for (int i = 1;i < n + 1;i++)
        {
            for (string& tmp : wordDict)
            {
                int m = tmp.size();
                if (i >= m)
                {
                    string t = s.substr(i - m, m);
                    if (t == tmp && dp[i - m])
                        dp[i] = true;break;
                }
            }
        }
        return dp[n];
    }
};
int main()
{
    vector<string> v = { "leet","code" };
    Solution().wordBreak("leetcode", v);
	return 0;
}